<!--
* description: 门店销售扩展信息
* author: dinggf
* createdDate: 2019-10-23
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-export-converts="exportConverts"
      :dynamic-is-show-more-btn="true"
      :dynamic-is-show-select="false"
      :dynamic-un-form-fields="unFormField"
    />

    <edit
      :key="editPopupsKey"
      :org-id="orgId"
      :showdlr-id="showdlrId"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      @close="close"
    />
  </div>
</template>

<script>
import { orgApis } from '@/api/apiList/org'
import OneTableTemplate from '@/components/templates/oneTable'
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import Vue from 'vue'
export default {
  name: 'DlrSales',
  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },
  mixins: [oneTableWithViewTemplateMixins],
  // props: {
  //   qryDlrId: { type: String, default: "" }
  // },  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(
      [to.path, 'orgDlrSalesEdit', 'orgDlrSalesEdit-Maintain'],
      function() {
        next()
      }
    )
  },
  data() {
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
      // 赋值给弹窗dlrid
      showdlrId: '',
      orgId: '',
      // queryDlrId: this.qryDlrId,
      editPopupsVisible: false,
      editPopupsKey: 'key1',
      editPopupsState: '',
      // svFields: '门店类型',
      // //设置是否显示更多按钮
      isMoreBtn: true,
      // 网格查询API配置对象
      apiConfig: orgApis.mdmOrgDlrQuerySaleList,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'),
          name: 'search',
          position: 'right',
          fuzzySearch: true,
          isMust: false
        }, // 查询
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          clickEvent: () => this.export(),
          text: this.$t('sys.button.export'),
          name: 'export',
          position: 'left'
        }, // 导出
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          name: 'reset',
          position: 'right',
          isMust: false
        } // 重置
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
            .tableComponents
          : [
            // 组织类型（值列表）
            {
              compKey: 'compKey1',
              labelName: '品牌：',
              codeField: 'carBrandCode', // 品牌，目前中台报错。
              isMul: false,
              component: () => import('@/components/org/carBrand/carBrand'),
              type: 'dropdownList',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '门店：',
              codeField: 'dlrId', // codeField应该为dlrId，但是目前中台报错。
              textField: 'dlrShortName',
              component: () => import('@/components/org/orgDlr'),
              type: 'propus',
              isMust: true
            }, // 门店简称
            {
              compKey: 'compKey3',
              labelName: '门店类型：',
              codeField: 'dlrType',
              lookuptype: 'PA0072',
              isMul: false,
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              fuzzySearch: true,
              isMust: true
            }, // 门店类型
            {
              compKey: 'compKey5',
              labelName: '门店编码：',
              span: 6,
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              fuzzySearch: true,
              isMust: true
            }, // 门店编码
            {
              compKey: 'compKey6',
              labelName: '门店名称：',
              span: 6,
              codeField: 'dlrShortName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: false
            }, // 门店名称
            {
              compKey: 'compKey4',
              labelName: '含已停用门店：',
              codeField: 'isEnable',
              isRequire: true,
              span: 6,
              component: () => import('@/components/org/isEnable/isEnable'),
              type: 'checkbox',
              isMust: false
            } // 含已停用门店
          ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols.length >
          0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].tableCols
          : [
            {
              prop: 'controlBtn',
              label: this.$t('sys.content.operate'),
              codeField: 'controlBtn',
              width: 60,
              align: 'center',
              fixed: true,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey0',
                  align: 'center',
                  labelName: this.$t('sys.button.edit'),
                  codeField: 'editControlBtn',
                  clickEvent: this.handleClick,
                  component: () => import('@/components/org/linkButton')
                }
              ]
            },
            {
              prop: 'carBrandCn',
              label: this.$t('org.label.carBrandCn'),
              width: 100,
              align: 'center'
            },
            {
              prop: 'carBrandCode',
              label: this.$t('ve.label.carBrandCode'),
              width: null,
              align: 'center',
              hidden: true
            },
            {
              prop: 'dlrTypeName',
              label: '门店类型',
              width: 100,
              align: 'center'
            },
            {
              prop: 'dlrShortName',
              label: '门店',
              width: 100,
              align: 'center'
            },
            {
              prop: 'orgId',
              label: 'orgId',
              width: 150,
              align: 'center',
              hidden: true
            },
            {
              prop: 'dlrTypeName',
              label: '门店类型名称',
              width: 120,
              align: 'center',
              hidden: true
            },
            {
              prop: 'dlrId',
              label: '门店Id',
              width: 120,
              align: 'center',
              hidden: true
            },
            {
              prop: 'dlrCode',
              label: '门店编码',
              width: 100,
              align: 'center'
            },
            {
              prop: 'dlrLevelName',
              label: '门店等级',
              width: 90,
              align: 'center'
            },
            {
              prop: 'driveTypeName',
              label: '门店规模',
              width: null,
              align: 'center'
            }, // 中台目前缺失该字段。
            {
              prop: 'driveType',
              label: '门店规模',
              width: null,
              align: 'center',
              hidden: true
            },
            {
              prop: 'linkAddr',
              label: '门店地址',
              width: 200,
              align: 'center'
            }, // 中台目前缺失该字段。（API文档没有该字段）

            {
              prop: 'zip',
              label: '邮编',
              width: 150,
              align: 'center',
              hidden: true
            },
            // { prop: "", label: "销售品牌", width: 150, align: "center" },  //中台目前缺失该字段。
            { prop: 'areaName', label: '地区', width: 90, align: 'center' },
            {
              prop: 'bigAreaName',
              label: '大区',
              width: null,
              align: 'center'
            },
            {
              prop: 'smallAreaName',
              label: '小区',
              width: null,
              align: 'center'
            },
            {
              prop: 'provinceName',
              label: '省份',
              width: 80,
              align: 'center'
            },
            { prop: 'cityName', label: '城市', width: 80, align: 'center' },
            {
              prop: 'saleTel',
              label: '销售热线',
              width: 100,
              align: 'center'
            },
            {
              prop: 'saleFax',
              label: '传真(售前)',
              width: 100,
              align: 'center'
            },
            {
              prop: 'saleEmail',
              label: '销售联络EMAIL',
              width: 100,
              align: 'center'
            },
            {
              prop: 'sapDlrId',
              label: 'SAP编码',
              width: null,
              align: 'center',
              hidden: true
            },
            {
              prop: 'dlrAnswerCode',
              label: 'ANSWER编码',
              width: 100,
              align: 'center',
              hidden: false
            },
            {
              prop: 'climateStatus',
              label: '气候状态',
              width: null,
              align: 'center',
              hidden: true
            },
            // {
            //   prop: "climateStatusName",
            //   label: "气候状态",
            //   width: null,
            //   align: "center",
            // },
            {
              prop: 'emissionStandard',
              label: '排放标准',
              width: null,
              align: 'center'
            },
            {
              prop: 'linkManAddr',
              label: '整车收货地址',
              width: 120,
              align: 'center'
            },
            { prop: 'isEnable', label: '状态', width: 80, align: 'center' }
            // { prop: "updateControlId", label: "并发控制Id", width: 80, align: "center" }, //中台目前没有
          ],
      // 查询条件
      formField: this.$utils.getFormField(
        this,
        {
          carBrandCode: '1', // 中台暂时没有
          dlrId: '', // 中台暂时没有
          dlrType: '',
          dlrCode: '',
          dlrShortName: '',
          isEnable: '0'
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
      unFormField: {
        // carBrandCode: "",
        // dlrId: "",
      },
      exportConverts: {
        isEnable: {
          convert: 'kvs',
          kvs: {
            '1': '是',
            '0': '否'
          }
        }
      }
    }
  },
  mounted() {
    this.queryTable(1)
  },
  methods: {
    // 导出
    export() {
      const _this = this
      const thst = this.$refs.multipleTable
      thst.apiConfig = orgApis.exportMdmOrgDlrSaleInfo
      this.exportExcel()
      _this.$nextTick(() => {
        thst.apiConfig = orgApis.mdmOrgDlrQuerySaleList
      })
    },
    handleClick(index) {
      const that = this.$refs.multipleTable
      // const that = this.$refs.multipleTable;
      this.showdlrId = that.$refs.multipleTable.data[index].dlrId
      this.edit(index)
    }
  }
}
</script>

<style lang='scss' scoped>
// /deep/ .el-row .table-col.el-col.el-col-24 .el-col.el-col-4 {
//       width: 150px !important;
//       margin-top: 4px !important;
// }
// /deep/ .el-row .table-col.el-col.el-col-24 .el-col.el-col-2 {
//      text-align: right !important;
// }
// /deep/ #searchFormGroup .el-row .el-col .el-col >label{
//          width: 40% !important;
// }
</style>
